#include "../../lvgl/lvgl.h"
#include "ui.h"

lv_obj_t * ui_page2 = NULL;

lv_obj_t * home_kongtiao = NULL;
lv_obj_t * home_led = NULL;
lv_obj_t * home_chuanglian = NULL;
lv_obj_t * home_jiashiqi = NULL;

lv_obj_t * sleep_kongtiao = NULL;
lv_obj_t * sleep_led = NULL;
lv_obj_t * sleep_chuanglian = NULL;
lv_obj_t * sleep_jiashiqi = NULL;

lv_obj_t * windy_kongtiao = NULL;
lv_obj_t * windy_led = NULL;
lv_obj_t * windy_chuanglian = NULL;
lv_obj_t * windy_jiashiqi = NULL;

lv_obj_t * home_kongtiao_txt = NULL;
lv_obj_t * home_LED_txt = NULL;
lv_obj_t * home_chuanglian_txt = NULL;

lv_obj_t * sleep_kongtiao_txt = NULL;
lv_obj_t * sleep_LED_txt = NULL;
lv_obj_t * sleep_chuanglian_txt = NULL;

lv_obj_t * windy_kongtiao_txt = NULL;
lv_obj_t * windy_LED_txt = NULL;
lv_obj_t * windy_chuanglian_txt = NULL;

int home_kongtiao_value;
int home_led_value;
int home_chuanglian_value;

int sleep_kongtiao_value;
int sleep_led_value;
int sleep_chuanglian_value;

int windy_kongtiao_value;
int windy_led_value;
int windy_chuanglian_value;

static void event_Demo(lv_event_t *e)
{
    lv_scr_load(ui_page1);
}

static void event_Modify(lv_event_t *e)
{
    lv_scr_load(ui_page3);
}

void Page_2()
{
    //创建副屏幕
    ui_page2 = lv_obj_create(NULL);
    lv_obj_clear_flag(ui_page2, LV_OBJ_FLAG_SCROLLABLE); //清除滚动标志

    //创建标题标签
    lv_obj_t * Title = lv_label_create(ui_page2);
    lv_obj_set_width(Title, lv_pct(50));
    lv_obj_set_height(Title, lv_pct(15));
    lv_obj_set_x(Title, lv_pct(0));
    lv_obj_set_y(Title, lv_pct(4));
    lv_obj_set_align(Title , LV_ALIGN_TOP_MID);
    lv_obj_add_style(Title, &style_50, 0);             //给标签添加字体风格
    lv_label_set_text(Title, "模式设置界面");


    //创建切换到主页面的按钮，设定好标签文本以及回调函数
    lv_obj_t * Demo = lv_btn_create(ui_page2);
    lv_obj_set_width(Demo, lv_pct(20));
    lv_obj_set_height(Demo, lv_pct(10));
    lv_obj_set_x(Demo, lv_pct(10));
    lv_obj_set_y(Demo, lv_pct(5));
    lv_obj_set_align(Demo, LV_ALIGN_TOP_LEFT);
    lv_obj_t * Demo_label = lv_label_create(Demo);
    lv_obj_set_width(Demo_label, lv_pct(100));
    lv_obj_set_height(Demo_label, lv_pct(100));
    lv_obj_set_align(Demo_label , LV_ALIGN_CENTER);
    lv_obj_add_style(Demo_label, &style_32, 0); //给标签添加字体风格
    lv_label_set_text(Demo_label, "主页面");
    lv_obj_add_event_cb(Demo, event_Demo, LV_EVENT_CLICKED, NULL);

    //创建切换到修改处置的按钮，设定好标签文本以及回调函数
    lv_obj_t * modify = lv_btn_create(ui_page2);
    lv_obj_set_width(modify, lv_pct(20));
    lv_obj_set_height(modify, lv_pct(10));
    lv_obj_set_x(modify, lv_pct(-10));
    lv_obj_set_y(modify, lv_pct(5));
    lv_obj_set_align(modify, LV_ALIGN_TOP_RIGHT);
    lv_obj_t * modify_label = lv_label_create(modify);
    lv_obj_set_width(modify_label, lv_pct(100));
    lv_obj_set_height(modify_label, lv_pct(100));
    lv_obj_set_align(modify_label , LV_ALIGN_CENTER);
    lv_obj_add_style(modify_label, &style_32, 0); //给标签添加字体风格
    lv_label_set_text(modify_label, "修改初值");
    lv_obj_add_event_cb(modify, event_Modify, LV_EVENT_CLICKED, NULL);

    //创建场景设置区域
    lv_obj_t * area1 = lv_obj_create(ui_page2);
    lv_obj_set_width(area1, lv_pct(80));
    lv_obj_set_height(area1, lv_pct(80));
    lv_obj_set_x(area1, lv_pct(0));
    lv_obj_set_y(area1, lv_pct(10));
    lv_obj_set_align(area1, LV_ALIGN_CENTER);
    lv_obj_clear_flag(area1, LV_OBJ_FLAG_SCROLLABLE);   //清除滚动标志

    //创建回家模式标签
    lv_obj_t * Home = lv_label_create(area1);
    lv_obj_set_width(Home, lv_pct(25));
    lv_obj_set_height(Home, lv_pct(15));
    lv_obj_set_x(Home, lv_pct(15));
    lv_obj_set_y(Home, lv_pct(1));
    lv_obj_add_style(Home, &style_32_bule, 0);  
    lv_label_set_text(Home, "回家模式");

    //创建睡眠模式标签
    lv_obj_t * Sleep = lv_label_create(area1);
    lv_obj_set_width(Sleep, lv_pct(25));
    lv_obj_set_height(Sleep, lv_pct(15));
    lv_obj_set_x(Sleep, lv_pct(45));
    lv_obj_set_y(Sleep, lv_pct(1));
    lv_obj_add_style(Sleep, &style_32_bule, 0);  
    lv_label_set_text(Sleep, "睡眠模式");

    //创建通风模式标签
    lv_obj_t * Windy = lv_label_create(area1);
    lv_obj_set_width(Windy, lv_pct(25));
    lv_obj_set_height(Windy, lv_pct(15));
    lv_obj_set_x(Windy, lv_pct(75));
    lv_obj_set_y(Windy, lv_pct(1));
    lv_obj_add_style(Windy, &style_32_bule, 0);  
    lv_label_set_text(Windy, "通风模式");
    
    //创建空调标签
    lv_obj_t * kongtiao = lv_label_create(area1);
    lv_obj_set_width(kongtiao, lv_pct(15));
    lv_obj_set_height(kongtiao, lv_pct(10));
    lv_obj_set_x(kongtiao, lv_pct(0));
    lv_obj_set_y(kongtiao, lv_pct(20));
    lv_obj_add_style(kongtiao, &style_32, 0);  
    lv_label_set_text(kongtiao, "空调");

    //创建灯光标签
    lv_obj_t * LED = lv_label_create(area1);
    lv_obj_set_width(LED, lv_pct(15));
    lv_obj_set_height(LED, lv_pct(10));
    lv_obj_set_x(LED, lv_pct(0));
    lv_obj_set_y(LED, lv_pct(45));
    lv_obj_add_style(LED, &style_32, 0);  
    lv_label_set_text(LED, "灯光");

    //创建窗帘标签
    lv_obj_t * chuanglian = lv_label_create(area1);
    lv_obj_set_width(chuanglian, lv_pct(15));
    lv_obj_set_height(chuanglian, lv_pct(10));
    lv_obj_set_x(chuanglian, lv_pct(0));
    lv_obj_set_y(chuanglian, lv_pct(70));
    lv_obj_add_style(chuanglian, &style_32, 0);  
    lv_label_set_text(chuanglian, "窗帘");

    //创建加湿器标签
    lv_obj_t * jiashiqi = lv_label_create(area1);
    lv_obj_set_width(jiashiqi, lv_pct(15));
    lv_obj_set_height(jiashiqi, lv_pct(10));
    lv_obj_set_x(jiashiqi, lv_pct(0));
    lv_obj_set_y(jiashiqi, lv_pct(93));
    lv_obj_add_style(jiashiqi, &style_32, 0);  
    lv_label_set_text(jiashiqi, "加湿器");

    //创建四个开关按钮，分别对应回家模式四个电器的开关
    home_kongtiao = lv_switch_create(area1);
    lv_obj_set_width(home_kongtiao, lv_pct(6));
    lv_obj_set_height(home_kongtiao, lv_pct(6));
    lv_obj_set_x(home_kongtiao, lv_pct(25));
    lv_obj_set_y(home_kongtiao, lv_pct(20));
    // lv_obj_add_state(home_kongtiao, LV_STATE_CHECKED);

    home_led = lv_switch_create(area1);
    lv_obj_set_width(home_led, lv_pct(6));
    lv_obj_set_height(home_led, lv_pct(6));
    lv_obj_set_x(home_led, lv_pct(25));
    lv_obj_set_y(home_led, lv_pct(45));
    // lv_obj_add_state(home_led, LV_STATE_CHECKED);

    home_chuanglian = lv_switch_create(area1);
    lv_obj_set_width(home_chuanglian, lv_pct(6));
    lv_obj_set_height(home_chuanglian, lv_pct(6));
    lv_obj_set_x(home_chuanglian, lv_pct(25));
    lv_obj_set_y(home_chuanglian, lv_pct(70));
    // lv_obj_add_state(home_chuanglian, LV_STATE_CHECKED);

    home_jiashiqi = lv_switch_create(area1);
    lv_obj_set_width(home_jiashiqi, lv_pct(6));
    lv_obj_set_height(home_jiashiqi, lv_pct(6));
    lv_obj_set_x(home_jiashiqi, lv_pct(25));
    lv_obj_set_y(home_jiashiqi, lv_pct(93));
    // lv_obj_add_state(home_jiashiqi, LV_STATE_CHECKED);

    //创建四个开关按钮，分别对应睡眠模式四个电器的开关
    sleep_kongtiao = lv_switch_create(area1);
    lv_obj_set_width(sleep_kongtiao, lv_pct(6));
    lv_obj_set_height(sleep_kongtiao, lv_pct(6));
    lv_obj_set_x(sleep_kongtiao, lv_pct(55));
    lv_obj_set_y(sleep_kongtiao, lv_pct(20));
    // lv_obj_add_state(sleep_kongtiao, LV_STATE_CHECKED);

    sleep_led = lv_switch_create(area1);
    lv_obj_set_width(sleep_led, lv_pct(6));
    lv_obj_set_height(sleep_led, lv_pct(6));
    lv_obj_set_x(sleep_led, lv_pct(55));
    lv_obj_set_y(sleep_led, lv_pct(45));

    sleep_chuanglian = lv_switch_create(area1);
    lv_obj_set_width(sleep_chuanglian, lv_pct(6));
    lv_obj_set_height(sleep_chuanglian, lv_pct(6));
    lv_obj_set_x(sleep_chuanglian, lv_pct(55));
    lv_obj_set_y(sleep_chuanglian, lv_pct(70));

    sleep_jiashiqi = lv_switch_create(area1);
    lv_obj_set_width(sleep_jiashiqi, lv_pct(6));
    lv_obj_set_height(sleep_jiashiqi, lv_pct(6));
    lv_obj_set_x(sleep_jiashiqi, lv_pct(55));
    lv_obj_set_y(sleep_jiashiqi, lv_pct(93));
    // lv_obj_add_state(sleep_jiashiqi, LV_STATE_CHECKED);

    //创建四个开关按钮，分别对应通风模式四个电器的开关
    windy_kongtiao = lv_switch_create(area1);
    lv_obj_set_width(windy_kongtiao, lv_pct(6));
    lv_obj_set_height(windy_kongtiao, lv_pct(6));
    lv_obj_set_x(windy_kongtiao, lv_pct(85));
    lv_obj_set_y(windy_kongtiao, lv_pct(20));

    windy_led = lv_switch_create(area1);
    lv_obj_set_width(windy_led, lv_pct(6));
    lv_obj_set_height(windy_led, lv_pct(6));
    lv_obj_set_x(windy_led, lv_pct(85));
    lv_obj_set_y(windy_led, lv_pct(45));

    windy_chuanglian = lv_switch_create(area1);
    lv_obj_set_width(windy_chuanglian, lv_pct(6));
    lv_obj_set_height(windy_chuanglian, lv_pct(6));
    lv_obj_set_x(windy_chuanglian, lv_pct(85));
    lv_obj_set_y(windy_chuanglian, lv_pct(70));
    // lv_obj_add_state(windy_chuanglian, LV_STATE_CHECKED);

    windy_jiashiqi = lv_switch_create(area1);
    lv_obj_set_width(windy_jiashiqi, lv_pct(6));
    lv_obj_set_height(windy_jiashiqi, lv_pct(6));
    lv_obj_set_x(windy_jiashiqi, lv_pct(85));
    lv_obj_set_y(windy_jiashiqi, lv_pct(93));

    //创建三个标签，分别对应回家模式下空调、灯光、窗帘的初值
    home_kongtiao_txt = lv_label_create(area1);
    lv_obj_set_width(home_kongtiao_txt, lv_pct(30));
    lv_obj_set_height(home_kongtiao_txt, lv_pct(13));
    lv_obj_set_x(home_kongtiao_txt, lv_pct(8));
    lv_obj_set_y(home_kongtiao_txt, lv_pct(30));
    lv_obj_add_style(home_kongtiao_txt, &style_32, 0);  

    home_LED_txt = lv_label_create(area1);
    lv_obj_set_width(home_LED_txt, lv_pct(30));
    lv_obj_set_height(home_LED_txt, lv_pct(13));
    lv_obj_set_x(home_LED_txt, lv_pct(8));
    lv_obj_set_y(home_LED_txt, lv_pct(55));
    lv_obj_add_style(home_LED_txt, &style_32, 0);  

    home_chuanglian_txt = lv_label_create(area1);
    lv_obj_set_width(home_chuanglian_txt, lv_pct(30));
    lv_obj_set_height(home_chuanglian_txt, lv_pct(13));
    lv_obj_set_x(home_chuanglian_txt, lv_pct(8));
    lv_obj_set_y(home_chuanglian_txt, lv_pct(80));
    lv_obj_add_style(home_chuanglian_txt, &style_32, 0);  
    
    //创建三个标签，分别对应睡眠模式下空调、灯光、窗帘的初值
    sleep_kongtiao_txt = lv_label_create(area1);
    lv_obj_set_width(sleep_kongtiao_txt, lv_pct(30));
    lv_obj_set_height(sleep_kongtiao_txt, lv_pct(13));
    lv_obj_set_x(sleep_kongtiao_txt, lv_pct(38));
    lv_obj_set_y(sleep_kongtiao_txt, lv_pct(30));
    lv_obj_add_style(sleep_kongtiao_txt, &style_32, 0);  

    sleep_LED_txt = lv_label_create(area1);
    lv_obj_set_width(sleep_LED_txt, lv_pct(30));
    lv_obj_set_height(sleep_LED_txt, lv_pct(13));
    lv_obj_set_x(sleep_LED_txt, lv_pct(38));
    lv_obj_set_y(sleep_LED_txt, lv_pct(55));
    lv_obj_add_style(sleep_LED_txt, &style_32, 0);  

    sleep_chuanglian_txt = lv_label_create(area1);
    lv_obj_set_width(sleep_chuanglian_txt, lv_pct(30));
    lv_obj_set_height(sleep_chuanglian_txt, lv_pct(13));
    lv_obj_set_x(sleep_chuanglian_txt, lv_pct(38));
    lv_obj_set_y(sleep_chuanglian_txt, lv_pct(80));
    lv_obj_add_style(sleep_chuanglian_txt, &style_32, 0);  

    //创建三个标签，分别对应通风模式下空调、灯光、窗帘的初值
    windy_kongtiao_txt = lv_label_create(area1);
    lv_obj_set_width(windy_kongtiao_txt, lv_pct(30));
    lv_obj_set_height(windy_kongtiao_txt, lv_pct(13));
    lv_obj_set_x(windy_kongtiao_txt, lv_pct(68));
    lv_obj_set_y(windy_kongtiao_txt, lv_pct(30));
    lv_obj_add_style(windy_kongtiao_txt, &style_32, 0);  
    
    windy_LED_txt = lv_label_create(area1);
    lv_obj_set_width(windy_LED_txt, lv_pct(30));
    lv_obj_set_height(windy_LED_txt, lv_pct(13));
    lv_obj_set_x(windy_LED_txt, lv_pct(68));
    lv_obj_set_y(windy_LED_txt, lv_pct(55));
    lv_obj_add_style(windy_LED_txt, &style_32, 0);  

    windy_chuanglian_txt = lv_label_create(area1);
    lv_obj_set_width(windy_chuanglian_txt, lv_pct(30));
    lv_obj_set_height(windy_chuanglian_txt, lv_pct(13));
    lv_obj_set_x(windy_chuanglian_txt, lv_pct(68));
    lv_obj_set_y(windy_chuanglian_txt, lv_pct(80));
    lv_obj_add_style(windy_chuanglian_txt, &style_32, 0);  
    
}